package com.itheima.pratice.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Demo02 {//键盘录入一个字符串，统计每个字符出现的次数
    public static void main(String[] args) {
        System.out.println("请输入一个字符串");
        String s = new Scanner(System.in).nextLine();
        //建立HashMap
        HashMap<Character, Integer> hashMap = new HashMap<Character, Integer>();
        Integer count = 1;
        for(int i = 0;i<s.length()-1;i++){
           if(hashMap.containsKey(s.charAt(i))){
               count = hashMap.get(s.charAt(i))+1;
           }
           hashMap.put(s.charAt(i),count);
       }
        //遍历输出
        for (Map.Entry<Character, Integer> entry : hashMap.entrySet()) {
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }
    }
}
